from lucommon.models import *


# Create your models here.


class ClusterStatusEnum:
    CREATING = 0
    DONE = 1
    FAILED = 2
    DESTROY = 3


class ClusterTypeEnum:
    ETCD = "etcd"
    KUBERNETES = "kubernetes"


class Cluster(LuModel):
    status_choices = (
        (ClusterStatusEnum.CREATING, "创建中"),
        (ClusterStatusEnum.DONE, "创建成功"),
        (ClusterStatusEnum.FAILED, "创建失败"),
        (ClusterStatusEnum.DESTROY, "销毁"),
    )
    type_choices = [(attr, getattr(ClusterTypeEnum, attr)) for attr in dir(ClusterTypeEnum) if str(attr)[:2] != "__"]

    id = models.AutoField(primary_key=True)
    name = models.CharField(max_length=400, null=True)
    type = models.CharField(choices=type_choices, max_length=400)
    status = models.IntegerField(choices=status_choices, default=ClusterStatusEnum.CREATING)
    config = models.JSONField(null=True)
    created_at = models.DateTimeField(null=True, auto_now_add=True)
    updated_at = models.DateTimeField(null=True, auto_now=True)

    class Meta:
        db_table = "deploy_cluster"
